function checkAuth(wxCode,callback) {
  console.log("go to checkAuth")
  var that = this;
  var app = getApp();
  wx.showLoading({
    title: '数据加载中'
  });
  if (wxCode == '') {
    wx.hideLoading();
    wx.showModal({
      title: '提示',
      content: '获取授权信息失败',
      showCancel: false
    })
    wx.navigateBack({
      url: '../sign/sign',
    })
  }else{
    wx.hideLoading();
    console.log("callback--checkAuth")
    callback();
  }
}

function checkSign(wxCode,callback){
  var app = getApp();
  console.log("go to checkSign")
  wx.showLoading({
    title: '数据加载中'
  })
  wx.request({
    url: app.globalData.mpurl + 'user/state',
    data: {
      wxCode: wxCode,
    },
    success: function (res) {
      res = res.data;
      wx.hideLoading();
      if (res.code == '00') {
        wx.setStorageSync('openId', res.data.openId);
        wx.setStorageSync('sessionKey', res.data.sessionKey);
        callback();
      } else {
        console.log("请先登录");
        wx.showModal({
          title: '提示',
          content: '请先登录',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '../sign/sign',
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    },
    complete: function () {
      wx.hideLoading();
    }
  })
}
function check(wxCode,callback){
  wx.login({
    success: function (res) {
      console.log("wxCode : "+res.code)

      checkAuth(res.code, function () {

        checkSign(res.code, function () {

          callback();
        })
      })
    }
  })
 
}

module.exports.checkAuth = checkAuth
module.exports.checkSign = checkSign
module.exports.check = check